package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.IOException;
import java.time.Duration;
import java.util.List;

public class BankPage extends Utils {
    public static String url="http://8.155.1.153:8081/repo/index";
    public BankPage() {
        super(url);
    }


    public void checkPageRight() throws IOException {
        //查看页面关键元素
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[3]/div/div/div[2]/div/div/div/div/div/div[2]/button"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[3]/div/div/div[2]/div/div/div/div/div/div[1]/button"));
        driver.findElement(By.xpath("//*[@id=\"name\"]"));
        driver.findElement(By.xpath("//*[@id=\"mode\"]"));
        driver.findElements(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[1]/button"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[2]/button"));
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName() + "BankPage");
    }

    public void SearchPractice() throws IOException {
        //输入名称
        driver.findElement(By.xpath("//*[@id=\"name\"]")).sendKeys("111");
        //点击状态栏
        driver.findElement(By.xpath("//*[@id=\"mode\"]")).click();
        driver.findElement(By.xpath("//div[text()='问卷']")).click();
        //查询
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[3]/div/div/div[2]/div/div/div/div/div/div[2]/button")).click();
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[1]"));//确认结果
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[3]/div/div/div[2]/div/div/div/div/div/div[1]/button")).click();//重置
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[3]/td[4]/span"));//确认结果
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }
    public  void NewProject() throws InterruptedException, IOException {
        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[1]/button")).click();

        // 定位抽屉主体
        WebElement drawerBody = driver.findElement(By.className("ant-drawer-body"));

        // 填写题库名称
        WebElement nameInput = drawerBody.findElement(By.cssSelector("#name"));
        nameInput.clear();
        nameInput.sendKeys("自动化测试题库");

        // 选择题库类型
        WebElement typeDropdown = drawerBody.findElement(By.cssSelector("#mode"));
        typeDropdown.click();
        WebElement questionnaireOption = driver.findElement(By.xpath("//div[text()='问卷']"));
        questionnaireOption.click();

        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());

        // 等待footer出现
        WebElement drawerFooter = wait.until(ExpectedConditions.visibilityOfElementLocated(
                By.className("ant-drawer-footer")));
        // 等待按钮可点击
        WebElement confirmButton = wait.until(ExpectedConditions.elementToBeClickable(
                By.cssSelector("div.ant-drawer-footer button.ant-btn-primary")));
        confirmButton.click();

        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());

    }

    public void ExamSearch() throws IOException {
        //点击试题管理按钮
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[3]/td[9]/div/div[3]/a")).click();

        //查询
        // 定位抽屉主体
        WebElement drawerBody = driver.findElement(By.className("ant-drawer-body"));
        WebElement modeInput = drawerBody.findElement(By.cssSelector("#mode"));
        modeInput.click();
        driver.findElement(By.xpath("//div[text()='考试']")).click();
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        drawerBody.findElement(By.cssSelector("button.ant-btn-primary")).click();
        driver.navigate().back();
    }
}
